{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Ex1 - Getting and knowing your Data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 1. Go to https://www.kaggle.com/openfoodfacts/world-food-facts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  Step 2. Download the dataset to your computer and unzip it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 3. Use the csv file and assign it to a dataframe called food"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "//anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py:2723: DtypeWarning: Columns (0,3,5,27,36) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  interactivity=interactivity, compiler=compiler, result=result)\n"
     ]
    }
   ],
   "source": [
    "food = pd.read_csv('/Users/guilhermeoliveira/Desktop/world-food-facts/FoodFacts.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 4. See the first 5 entries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>url</th>\n",
       "      <th>creator</th>\n",
       "      <th>created_t</th>\n",
       "      <th>created_datetime</th>\n",
       "      <th>last_modified_t</th>\n",
       "      <th>last_modified_datetime</th>\n",
       "      <th>product_name</th>\n",
       "      <th>generic_name</th>\n",
       "      <th>quantity</th>\n",
       "      <th>...</th>\n",
       "      <th>caffeine_100g</th>\n",
       "      <th>taurine_100g</th>\n",
       "      <th>ph_100g</th>\n",
       "      <th>fruits_vegetables_nuts_100g</th>\n",
       "      <th>collagen_meat_protein_ratio_100g</th>\n",
       "      <th>cocoa_100g</th>\n",
       "      <th>chlorophyl_100g</th>\n",
       "      <th>carbon_footprint_100g</th>\n",
       "      <th>nutrition_score_fr_100g</th>\n",
       "      <th>nutrition_score_uk_100g</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000000000000012866</td>\n",
       "      <td>http://world-en.openfoodfacts.org/product/0000...</td>\n",
       "      <td>date-limite-app</td>\n",
       "      <td>1447004364</td>\n",
       "      <td>2015-11-08T17:39:24Z</td>\n",
       "      <td>1447004364</td>\n",
       "      <td>2015-11-08T17:39:24Z</td>\n",
       "      <td>Poêlée à la sarladaise</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0000000024600</td>\n",
       "      <td>http://world-en.openfoodfacts.org/product/0000...</td>\n",
       "      <td>date-limite-app</td>\n",
       "      <td>1434530704</td>\n",
       "      <td>2015-06-17T08:45:04Z</td>\n",
       "      <td>1434535914</td>\n",
       "      <td>2015-06-17T10:11:54Z</td>\n",
       "      <td>Filet de bœuf</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.46 kg</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0000000036252</td>\n",
       "      <td>http://world-en.openfoodfacts.org/product/0000...</td>\n",
       "      <td>tacinte</td>\n",
       "      <td>1422221701</td>\n",
       "      <td>2015-01-25T21:35:01Z</td>\n",
       "      <td>1422221855</td>\n",
       "      <td>2015-01-25T21:37:35Z</td>\n",
       "      <td>Lion Peanut x2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0000000039259</td>\n",
       "      <td>http://world-en.openfoodfacts.org/product/0000...</td>\n",
       "      <td>tacinte</td>\n",
       "      <td>1422221773</td>\n",
       "      <td>2015-01-25T21:36:13Z</td>\n",
       "      <td>1422221926</td>\n",
       "      <td>2015-01-25T21:38:46Z</td>\n",
       "      <td>Twix x2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0000000039529</td>\n",
       "      <td>http://world-en.openfoodfacts.org/product/0000...</td>\n",
       "      <td>teolemon</td>\n",
       "      <td>1420147051</td>\n",
       "      <td>2015-01-01T21:17:31Z</td>\n",
       "      <td>1439141740</td>\n",
       "      <td>2015-08-09T17:35:40Z</td>\n",
       "      <td>Pack de 2 Twix</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 159 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 code                                                url  \\\n",
       "0  000000000000012866  http://world-en.openfoodfacts.org/product/0000...   \n",
       "1       0000000024600  http://world-en.openfoodfacts.org/product/0000...   \n",
       "2       0000000036252  http://world-en.openfoodfacts.org/product/0000...   \n",
       "3       0000000039259  http://world-en.openfoodfacts.org/product/0000...   \n",
       "4       0000000039529  http://world-en.openfoodfacts.org/product/0000...   \n",
       "\n",
       "           creator   created_t      created_datetime last_modified_t  \\\n",
       "0  date-limite-app  1447004364  2015-11-08T17:39:24Z      1447004364   \n",
       "1  date-limite-app  1434530704  2015-06-17T08:45:04Z      1434535914   \n",
       "2          tacinte  1422221701  2015-01-25T21:35:01Z      1422221855   \n",
       "3          tacinte  1422221773  2015-01-25T21:36:13Z      1422221926   \n",
       "4         teolemon  1420147051  2015-01-01T21:17:31Z      1439141740   \n",
       "\n",
       "  last_modified_datetime            product_name generic_name quantity  \\\n",
       "0   2015-11-08T17:39:24Z  Poêlée à la sarladaise          NaN      NaN   \n",
       "1   2015-06-17T10:11:54Z           Filet de bœuf          NaN  2.46 kg   \n",
       "2   2015-01-25T21:37:35Z          Lion Peanut x2          NaN      NaN   \n",
       "3   2015-01-25T21:38:46Z                 Twix x2          NaN      NaN   \n",
       "4   2015-08-09T17:35:40Z          Pack de 2 Twix          NaN      NaN   \n",
       "\n",
       "            ...           caffeine_100g taurine_100g ph_100g  \\\n",
       "0           ...                     NaN          NaN     NaN   \n",
       "1           ...                     NaN          NaN     NaN   \n",
       "2           ...                     NaN          NaN     NaN   \n",
       "3           ...                     NaN          NaN     NaN   \n",
       "4           ...                     NaN          NaN     NaN   \n",
       "\n",
       "  fruits_vegetables_nuts_100g collagen_meat_protein_ratio_100g cocoa_100g  \\\n",
       "0                         NaN                              NaN        NaN   \n",
       "1                         NaN                              NaN        NaN   \n",
       "2                         NaN                              NaN        NaN   \n",
       "3                         NaN                              NaN        NaN   \n",
       "4                         NaN                              NaN        NaN   \n",
       "\n",
       "  chlorophyl_100g carbon_footprint_100g nutrition_score_fr_100g  \\\n",
       "0             NaN                   NaN                     NaN   \n",
       "1             NaN                   NaN                     NaN   \n",
       "2             NaN                   NaN                     NaN   \n",
       "3             NaN                   NaN                     NaN   \n",
       "4             NaN                   NaN                     NaN   \n",
       "\n",
       "  nutrition_score_uk_100g  \n",
       "0                     NaN  \n",
       "1                     NaN  \n",
       "2                     NaN  \n",
       "3                     NaN  \n",
       "4                     NaN  \n",
       "\n",
       "[5 rows x 159 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 5. What is the number of observations in the dataset?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "65503"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food.shape #will give you both (observations/rows, columns)\n",
    "food.shape[0] #will give you only the observations/rows number"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 6. What is the number of columns in the dataset?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(65503, 159)\n",
      "159\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 65503 entries, 0 to 65502\n",
      "Columns: 159 entries, code to nutrition_score_uk_100g\n",
      "dtypes: float64(103), object(56)\n",
      "memory usage: 79.5+ MB\n"
     ]
    }
   ],
   "source": [
    "print food.shape #will give you both (observations/rows, columns)\n",
    "print food.shape[1] #will give you only the columns number\n",
    "\n",
    "#OR\n",
    "\n",
    "food.info() #Columns: 159 entries"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 7. Print the name of all the columns."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index([u'code', u'url', u'creator', u'created_t', u'created_datetime',\n",
       "       u'last_modified_t', u'last_modified_datetime', u'product_name',\n",
       "       u'generic_name', u'quantity',\n",
       "       ...\n",
       "       u'caffeine_100g', u'taurine_100g', u'ph_100g',\n",
       "       u'fruits_vegetables_nuts_100g', u'collagen_meat_protein_ratio_100g',\n",
       "       u'cocoa_100g', u'chlorophyl_100g', u'carbon_footprint_100g',\n",
       "       u'nutrition_score_fr_100g', u'nutrition_score_uk_100g'],\n",
       "      dtype='object', length=159)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 8. What is the name of 105th column?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'glucose_100g'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food.columns[104]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 9. What is the type of the observations of the 105th column?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('float64')"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food.dtypes['glucose_100g']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 10. How is the dataset indexed?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=65503, step=1)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food.index"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 11. What is the product name of the 19th observation?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Flat Leaf Parsley'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food.values[18][7]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
